package com.financing.platform.service.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.platform.dao.ICountInfoDao;
import com.financing.platform.dto.CountInfoDTO;
import com.financing.platform.service.ICountInfoService;
import com.financing.platform.util.SqlName;
import com.financing.platform.vo.AuthUserDetailedListVO;
import com.financing.platform.vo.OrderDetailedListVO;
import com.financing.platform.vo.SalesPerformanceVO;

/**
 * @Title: CountInfoServiceImpl.java
 * @Package com.financing.platform.service.impl
 * @Description: 统计信息查询service接口实现 
 * @author  qiye
 * @date 2014年10月31日 上午9:48:36
 * @version V1.0
 */
@Service("countInfoServiceImpl")
public class CountInfoServiceImpl extends BaseServiceImpl implements ICountInfoService {

	@Autowired
	private ICountInfoDao countInfoDaoImpl;
	
	public List<CountInfoDTO> queryCountInfoList(Map<String,Object> params) {
		return countInfoDaoImpl.queryCountInfoList(params);
	}
	
	public Map<String,Object> queryTotalCountInfo() throws SQLException{
		Map<String,Object> totalCountInfo = new HashMap<String,Object>();
		totalCountInfo.put("registPersonTotal", countInfoDaoImpl.queryTotalCount(SqlName.registPersonTotal));
		totalCountInfo.put("registVerifyPassTotal", countInfoDaoImpl.queryTotalCount(SqlName.registVerifyPassTotal));
		totalCountInfo.put("registVerifyNoPassTotal", countInfoDaoImpl.queryTotalCount(SqlName.registVerifyNoPassTotal));
		totalCountInfo.put("forWardNumTotal", countInfoDaoImpl.queryTotalCount(SqlName.forWardNumTotal));
		return totalCountInfo;
	}

	@Override
	public List<OrderDetailedListVO> queryOrderDetailedList(
			OrderDetailedListVO orderDetailedListVO)throws SQLException {
		return countInfoDaoImpl.queryOrderDetailedList(orderDetailedListVO);
	}

	@Override
	public int queryOrderDetailedListCount(OrderDetailedListVO orderDetailedListVO) throws SQLException{
		return countInfoDaoImpl.queryOrderDetailedListCount(orderDetailedListVO);
	}


	@Override
	public List<AuthUserDetailedListVO> queryAuthUserDetailedList(
			AuthUserDetailedListVO authUserDetailedListVO) throws SQLException {
		return countInfoDaoImpl.queryAuthUserDetailedList(authUserDetailedListVO);
	}

	@Override
	public int queryAuthUserDetailedListCount(
			AuthUserDetailedListVO authUserDetailedListVO) throws SQLException {
		return countInfoDaoImpl.queryAuthUserDetailedListCount(authUserDetailedListVO);
	}

	@Override
	public List<SalesPerformanceVO> querySalesPerformance(SalesPerformanceVO salesPerformanceVO) throws SQLException {
		
		List<SalesPerformanceVO> list = countInfoDaoImpl.querySalesPerformanceOrder(salesPerformanceVO);
		
		List<SalesPerformanceVO> list1 = countInfoDaoImpl.querySalesPerformanceRegister(salesPerformanceVO);
		
		for (SalesPerformanceVO queryOrder : list) {
			for (SalesPerformanceVO queryRegister : list1) {
				if(queryOrder.getServiceConsultantId().equals(queryRegister.getServiceConsultantId())){
					queryOrder.setRegisterCompanyCount(queryRegister.getRegisterCompanyCount());
					queryOrder.setRegisterPersonCount(queryRegister.getRegisterPersonCount());
				}
			}
		}
		
		List<SalesPerformanceVO> list2 = countInfoDaoImpl.querySalesPerformanceVisit(salesPerformanceVO);
		
		for (SalesPerformanceVO queryOrder : list) {
			for (SalesPerformanceVO queryVisit : list2) {
				if(queryOrder.getServiceConsultantId().equals(queryVisit.getServiceConsultantId())){
					queryOrder.setVisitCompanyCount(queryVisit.getVisitCompanyCount());
					queryOrder.setVisitPersonCount(queryVisit.getVisitPersonCount());
				}
			}
		}
		
		List<SalesPerformanceVO> list3 = countInfoDaoImpl.queryAccountFinancialCount(salesPerformanceVO);
		
		for (SalesPerformanceVO queryOrder : list) {
			for (SalesPerformanceVO queryVisit : list3) {
				if(queryOrder.getServiceConsultantId().equals(queryVisit.getServiceConsultantId())){
					queryOrder.setAccountFinancialCount(queryVisit.getAccountFinancialCount());
				}
			}
		}
		
		return list;
	}
	
	@Override
	public List<Map<String, Object>> queryOperateStatistics() throws SQLException {
		return countInfoDaoImpl.queryOperateStatistics();
	}
	
	@Override
	public List<Map<String, Object>> queryOrderCountByMonth()
			throws SQLException {
		return countInfoDaoImpl.queryOrderCountByMonth();
	}

	@Override
	public Map<String, Object> queryOrderUserPer() throws SQLException {
		return countInfoDaoImpl.queryOrderUserPer();
	}
	
	@Override
	public List<Map<String, Object>> queryFaUserRegisterByMonthCount(Map<String,Object> params) throws SQLException {
		return countInfoDaoImpl.queryFaUserRegisterByMonthCount(params);
	}
	
	@Override
	public List<Map<String, Object>> queryFaUserRoleCount(Map<String,Object> params) throws SQLException {
		return countInfoDaoImpl.queryFaUserRoleCount(params);
	}
	
	@Override
	public List<Map<String, Object>> queryFaUserCount(Map<String,Object> params) throws SQLException {
		return countInfoDaoImpl.queryFaUserCount(params);
	}

	@Override
	public List<Map<String, Object>> queryFaUserRoleProportion(Map<String, Object> params) throws SQLException {
		return countInfoDaoImpl.queryFaUserRoleProportion(params);
	}

	@Override
	public List<Map<String, Object>> queryOrderFaUserRoleProportion(Map<String, Object> params) throws SQLException {
		return countInfoDaoImpl.queryOrderFaUserRoleProportion(params);
	}

	@Override
	public List<Map<String, Object>> queryUserTotalSales(CountInfoDTO countInfo) throws SQLException {
		return countInfoDaoImpl.queryUserTotalSales(countInfo);
	}
	
}

	